package cn.good.wkm.frame.service.impl;

import cn.good.wkm.frame.dao.IUserDao;
import cn.good.wkm.frame.domain.po.User;
import cn.good.wkm.frame.domain.vo.UserVO;
import cn.good.wkm.frame.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author wkm
 * @Date 2024/10/17
 **/
@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private IUserDao userDao;

    @Override
    public List<UserVO> queryUserList() {
        List<UserVO> userVOList = new ArrayList<>();
        List<User> users = userDao.queryUserList();
        for(User user : users){
            UserVO userVO = UserVO.builder()
                    .userId(user.getUserId())
                    .userNickname(user.getUserNickname())
                    .userHead(user.getUserHead())
                    .build();
            userVOList.add(userVO);
        }
        return userVOList;
    }

    @Override
    public UserVO getUserInfo(int id) {
        User user = userDao.getUserInfo(id);
        UserVO userInfo = UserVO.builder()
                .userId(user.getUserId())
                .userNickname(user.getUserNickname())
                .userHead(user.getUserHead())
                .build();
        return userInfo;
    }

    @Override
    public int deleteUserById(Integer id) {
        return userDao.deleteUserById(id);
    }

    @Override
    public User addUserInfo(User user) {
        userDao.addUserInfo(user);
        return user;
    }

    @Override
    public int updateUserById(User user) {
        return userDao.updateUserById(user);
    }
}
